package com.dahua.messagesyncsh.business.mitsubishi.http;

/**
 * 返回工具类
 *
 * @author smec
 * 2021/8/13
 */
public class Result {

    /**
     * 成功但不带数据
     * 默认code和msg
     **/
    public static <T> Response<T> success() {
        return success(ResultEnum.SUCCESS);
    }

    /**
     * 成功且不带数据
     * code=ResultEnum.code
     * message=ResultEnum.message
     **/
    public static <T> Response<T> success(ResultEnum resultEnum) {
        Response<T> response = new Response<>();
        response.setCode(resultEnum.getCode());
        response.setMessage(resultEnum.getMessage());
        response.setData(null);
        return response;
    }

    /**
     * 成功且不带数据
     * 自定义code和msg
     **/
    public static <T> Response<T> success(String code, String msg) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(msg);
        response.setData(null);
        return response;
    }

    /**
     * 成功且带数据
     * 默认code和msg
     **/
    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setCode(ResultEnum.SUCCESS.getCode());
        response.setMessage(ResultEnum.SUCCESS.getMessage());
        response.setData(data);
        return response;
    }

    /**
     * 成功且带数据
     * code=ResultEnum.code
     * message=ResultEnum.message
     **/
    public static <T> Response<T> success(ResultEnum resultEnum, T data) {
        Response<T> response = new Response<>();
        response.setCode(resultEnum.getCode());
        response.setMessage(resultEnum.getMessage());
        response.setData(data);
        return response;
    }

    /**
     * 成功且带数据
     * 自定义 code 和 msg
     **/
    public static <T> Response<T> success(String code, String msg, T data) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(msg);
        response.setData(data);
        return response;
    }

    /**
     * 失败且不带数据
     * 默认code和msg
     **/
    public static <T> Response<T> fail() {
        return fail(ResultEnum.FAIL);
    }

    /**
     * 失败且不带数据
     * code=ResultEnum.code
     * message=ResultEnum.message
     **/
    public static <T> Response<T> fail(ResultEnum resultEnum) {
        Response<T> response = new Response<>();
        response.setCode(resultEnum.getCode());
        response.setMessage(resultEnum.getMessage());
        return response;
    }

    /**
     * 失败且不带数据
     * 自定义msg
     * code为ResultEnum.FAIL.code，
     */
    public static <T> Response<T> fail(String msg) {
        Response<T> response = new Response<>();
        response.setCode(ResultEnum.FAIL.getCode());
        response.setMessage(msg);
        return response;
    }

    /**
     * 失败且不带数据
     * 自定义code和msg
     */
    public static <T> Response<T> fail(String code, String msg) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(msg);
        return response;
    }

    /**
     * 失败且带数据
     * code=ResultEnum.code
     * message=ResultEnum.message
     **/
    public static <T> Response<T> fail(ResultEnum resultEnum, T data) {
        Response<T> response = new Response<>();
        response.setCode(resultEnum.getCode());
        response.setMessage(resultEnum.getMessage());
        response.setData(data);
        return response;
    }

    /**
     * 失败且带数据
     * 自定义code、msg和data
     */
    public static <T> Response<T> fail(String code, String msg, T data) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(msg);
        response.setData(data);
        return response;
    }

}
